<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Zend_Service_ReCaptcha - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.service.recaptcha.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.service.recaptcha.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.service.nirvanix.html">Zend_Service_Nirvanix</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.service.html">Zend_Service</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.service.short-url.html">Zend_Service_ShortUrl</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.service.recaptcha" class="section"><div class="info"><h1 class="title">Zend_Service_ReCaptcha</h1></div>
    

    <div class="section" id="zend.service.recaptcha.introduction"><div class="info"><h1 class="title">Introduction</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Service_ReCaptcha</span> provides a client for the <a href="http://recaptcha.net/" class="link external">&raquo; reCAPTCHA Web Service</a>.
            Per the reCAPTCHA site, &quot;reCAPTCHA is a free CAPTCHA service that
            helps to digitize books.&quot; Each reCAPTCHA requires the user to input
            two words, the first of which is the actual CAPTCHA, and the second
            of which is a word from some scanned text that Optical Character
            Recognition (OCR) software has been unable to identify.
            The assumption is that if a user correctly provides the first
            word, the second is likely correctly entered as well, and can be
            used to improve OCR software for digitizing books.
        </p>

        <p class="para">
            In order to use the reCAPTCHA service, you will need to <a href="http://recaptcha.net/whyrecaptcha.html" class="link external">&raquo; sign up for an
                account</a> and register one or more domains with the
            service in order to generate public and private keys.
        </p>
    </div>

    <div class="section" id="zend.service.recaptcha.simplestuse"><div class="info"><h1 class="title">Simplest use</h1></div>
        

        <p class="para">
            Instantiate a <span class="classname">Zend_Service_ReCaptcha</span> object, passing it
            your public and private keys:
        </p>

        <div class="example" id="zend.service.recaptcha.example-1"><div class="info"><p><b>Example #1 Creating an instance of the reCAPTCHA service</b></p></div>
            

            <pre class="programlisting brush: php">
$recaptcha = new Zend_Service_ReCaptcha($pubKey, $privKey);
</pre>

        </div>

        <p class="para">
            To render the reCAPTCHA, simply call the  <span class="methodname">getHTML()</span>
            method:
        </p>

        <div class="example" id="zend.service.recaptcha.example-2"><div class="info"><p><b>Example #2 Displaying the reCAPTCHA</b></p></div>
            

            <pre class="programlisting brush: php">
echo $recaptcha-&gt;getHTML();
</pre>

        </div>

        <p class="para">
            When the form is submitted, you should receive two fields,
            &#039;recaptcha_challenge_field&#039; and &#039;recaptcha_response_field&#039;. Pass
            these to the reCAPTCHA object&#039;s  <span class="methodname">verify()</span> method:
        </p>

        <div class="example" id="zend.service.recaptcha.example-3"><div class="info"><p><b>Example #3 Verifying the form fields</b></p></div>
            

            <pre class="programlisting brush: php">
$result = $recaptcha-&gt;verify(
    $_POST[&#039;recaptcha_challenge_field&#039;],
    $_POST[&#039;recaptcha_response_field&#039;]
);
</pre>

        </div>

        <p class="para">
            Once you have the result, test against it to see if it is valid. The
            result is a <span class="classname">Zend_Service_ReCaptcha_Response</span> object,
            which provides an  <span class="methodname">isValid()</span> method.
        </p>

        <div class="example" id="zend.service.recaptcha.example-4"><div class="info"><p><b>Example #4 Validating the reCAPTCHA</b></p></div>
            

            <pre class="programlisting brush: php">
if (!$result-&gt;isValid()) {
    // Failed validation
}
</pre>

        </div>

        <p class="para">
            It is even simpler to use <a href="zend.captcha.adapters.html#zend.captcha.adapters.recaptcha" class="link">the reCAPTCHA</a>
            <span class="classname">Zend_Captcha</span> adapter, or to use that adapter as a
            backend for the <a href="zend.form.standardElements.html#zend.form.standardElements.captcha" class="link">CAPTCHA form
                element</a>. In each case, the details of rendering and
            validating the reCAPTCHA are automated for you.
        </p>
    </div>

    <div class="section" id="zend.service.recaptcha.mailhide"><div class="info"><h1 class="title">Hiding email addresses</h1></div>
        

        <p class="para">
            <span class="classname">Zend_Service_ReCaptcha_MailHide</span> can be used to hide email
            addresses. It will replace a part of an email address with a link that opens a popup
            window with a reCAPTCHA challenge. Solving the challenge will reveal the complete
            email address.
        </p>

        <p class="para">
            In order to use this component you will need
            <a href="http://recaptcha.net/whyrecaptcha.html" class="link external">&raquo; an account</a> to generate
            public and private keys for the mailhide <acronym class="acronym">API</acronym>.
        </p>

        <div class="example" id="zend.service.recaptcha.mailhide.example-1"><div class="info"><p><b>Example #5 Using the mail hide component</b></p></div>
            

            <pre class="programlisting brush: php">
// The mail address we want to hide
$mail = &#039;mail@example.com&#039;;

// Create an instance of the mailhide component, passing it your public
// and private keys, as well as the mail address you want to hide
$mailHide = new Zend_Service_ReCaptcha_MailHide();
$mailHide-&gt;setPublicKey($pubKey);
$mailHide-&gt;setPrivateKey($privKey);
$mailHide-&gt;setEmail($mail);

// Display it
print($mailHide);
</pre>

        </div>

        <p class="para">
            The example above will display &quot;m...@example.com&quot; where &quot;...&quot; has a link that opens up
            a popup window with a reCAPTCHA challenge.
        </p>

        <p class="para">
            The public key, private key, and the email address can also be specified in the
            constructor of the class. A fourth argument also exists that enables you to set some
            options for the component. The available options are listed in the following table:

            <table id="zend.service.recaptcha.mailhide.options.table" class="doctable table"><div class="info"><caption><b>Zend_Service_ReCaptcha_MailHide options</b></caption></div>
                

                
                    <thead valign="middle">
                        <tr valign="middle">
                            <th>Option</th>
                            <th>Description</th>
                            <th>Expected Values</th>
                            <th>Default Value</th>
                        </tr>

                    </thead>


                    <tbody valign="middle" class="tbody">
                        <tr valign="middle">
                            <td align="left">linkTitle</td>
                            <td align="left">The title attribute of the link</td>
                            <td align="left">string</td>
                            <td align="left">&#039;Reveal this e-mail address&#039;</td>
                        </tr>


                        <tr valign="middle">
                            <td align="left">linkHiddenText</td>
                            <td align="left">The text that includes the popup link</td>
                            <td align="left">string</td>
                            <td align="left">&#039;...&#039;</td>
                        </tr>


                        <tr valign="middle">
                            <td align="left">popupWidth</td>
                            <td align="left">The width of the popup window</td>
                            <td align="left">int</td>
                            <td align="left">500</td>
                        </tr>


                        <tr valign="middle">
                            <td align="left">popupHeight</td>
                            <td align="left">The height of the popup window</td>
                            <td align="left">int</td>
                            <td align="left">300</td>
                        </tr>

                    </tbody>
                
            </table>

        </p>

        <p class="para">
            The configuration options can be set by sending them as the fourth argument to the
            constructor or by calling  <span class="methodname">setOptions($options)</span>, which takes
            an associative array or an instance of <a href="zend.config.html" class="link">Zend_Config</a>.
        </p>

        <div class="example" id="zend.service.recaptcha.mailhide.example-2"><div class="info"><p><b>Example #6 Generating many hidden email addresses</b></p></div>
            

            <pre class="programlisting brush: php">
// Create an instance of the mailhide component, passing it your public
// and private keys, as well as some configuration options
$mailHide = new Zend_Service_ReCaptcha_MailHide();
$mailHide-&gt;setPublicKey($pubKey);
$mailHide-&gt;setPrivateKey($privKey);
$mailHide-&gt;setOptions(array(
    &#039;linkTitle&#039; =&gt; &#039;Click me&#039;,
    &#039;linkHiddenText&#039; =&gt; &#039;+++++&#039;,
));

// The mail addresses we want to hide
$mailAddresses = array(
    &#039;mail@example.com&#039;,
    &#039;johndoe@example.com&#039;,
    &#039;janedoe@example.com&#039;,
);

foreach ($mailAddresses as $mail) {
    $mailHide-&gt;setEmail($mail);
    print($mailHide);
}
</pre>

        </div>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.service.nirvanix.html">Zend_Service_Nirvanix</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.service.html">Zend_Service</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.service.short-url.html">Zend_Service_ShortUrl</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.service.html">Zend_Service</a></li>
  <li><a href="zend.service.introduction.html">Introduction</a></li>
  <li><a href="zend.service.akismet.html">Zend_Service_Akismet</a></li>
  <li><a href="zend.service.amazon.html">Zend_Service_Amazon</a></li>
  <li><a href="zend.service.amazon.ec2.html">Zend_Service_Amazon_Ec2</a></li>
  <li><a href="zend.service.amazon.ec2.instance.html">Zend_Service_Amazon_Ec2: Instances</a></li>
  <li><a href="zend.service.amazon.ec2.windows.instance.html">Zend_Service_Amazon_Ec2: Windows Instances</a></li>
  <li><a href="zend.service.amazon.ec2.reserved.instance.html">Zend_Service_Amazon_Ec2: Reserved Instances</a></li>
  <li><a href="zend.service.amazon.ec2.cloudwatch.html">Zend_Service_Amazon_Ec2: CloudWatch Monitoring</a></li>
  <li><a href="zend.service.amazon.ec2.images.html">Zend_Service_Amazon_Ec2: Amazon Machine Images (AMI)</a></li>
  <li><a href="zend.service.amazon.ec2.ebs.html">Zend_Service_Amazon_Ec2: Elastic Block Storage (EBS)</a></li>
  <li><a href="zend.service.amazon.ec2.elasticip.html">Zend_Service_Amazon_Ec2: Elastic IP Addresses</a></li>
  <li><a href="zend.service.amazon.ec2.keypairs.html">Zend_Service_Amazon_Ec2: Keypairs</a></li>
  <li><a href="zend.service.amazon.ec2.zones.html">Zend_Service_Amazon_Ec2: Regions and Availability Zones</a></li>
  <li><a href="zend.service.amazon.ec2.securitygroups.html">Zend_Service_Amazon_Ec2: Security Groups</a></li>
  <li><a href="zend.service.amazon.s3.html">Zend_Service_Amazon_S3</a></li>
  <li><a href="zend.service.amazon.sqs.html">Zend_Service_Amazon_Sqs</a></li>
  <li><a href="zend.service.audioscrobbler.html">Zend_Service_Audioscrobbler</a></li>
  <li><a href="zend.service.delicious.html">Zend_Service_Delicious</a></li>
  <li><a href="zend.service.developergarden.html">Zend_Service_DeveloperGarden</a></li>
  <li><a href="zend.service.ebay.html">Zend_Service_Ebay</a></li>
  <li><a href="zend.service.ebay.finding.html">Zend_Service_Ebay_Finding</a></li>
  <li><a href="zend.service.flickr.html">Zend_Service_Flickr</a></li>
  <li><a href="zend.service.livedocx.html">Zend_Service_LiveDocx</a></li>
  <li><a href="zend.service.nirvanix.html">Zend_Service_Nirvanix</a></li>
  <li class="active"><a href="zend.service.recaptcha.html">Zend_Service_ReCaptcha</a></li>
  <li><a href="zend.service.short-url.html">Zend_Service_ShortUrl</a></li>
  <li><a href="zend.service.simpy.html">Zend_Service_Simpy</a></li>
  <li><a href="zend.service.slideshare.html">Zend_Service_SlideShare</a></li>
  <li><a href="zend.service.strikeiron.html">Zend_Service_StrikeIron</a></li>
  <li><a href="zend.service.strikeiron.bundled-services.html">Zend_Service_StrikeIron: Bundled Services</a></li>
  <li><a href="zend.service.strikeiron.advanced-uses.html">Zend_Service_StrikeIron: Advanced Uses</a></li>
  <li><a href="zend.service.technorati.html">Zend_Service_Technorati</a></li>
  <li><a href="zend.service.twitter.html">Zend_Service_Twitter</a></li>
  <li><a href="zend.service.windowsazure.html">Zend_Service_WindowsAzure</a></li>
  <li><a href="zend.service.windowsazure.storage.blob.html">Zend_Service_WindowsAzure_Storage_Blob</a></li>
  <li><a href="zend.service.windowsazure.diagnostics.manager.html">Zend_Service_WindowsAzure_Diagnostics_Manager</a></li>
  <li><a href="zend.service.windowsazure.storage.queue.html">Zend_Service_WindowsAzure_Storage_Queue</a></li>
  <li><a href="zend.service.windowsazure.storage.table.html">Zend_Service_WindowsAzure_Storage_Table</a></li>
  <li><a href="zend.service.yahoo.html">Zend_Service_Yahoo</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>